// 快速排序示例：
Array.prototype.quickSort = function () {
    const rec = (arr) => {
        if (arr.length === 1) {
            return arr
        }
        const left = []
        const right = []
        const mid = arr[0]
        for (let i = 1; i < arr.length; i += 1) {
            if (arr[i] < mid) {
                left.push(arr[i])
            } else {
                right.push(arr[i])
            }
        }
        return [...rec(left), mid, ...rec(right)]
    }
    rec(this)
    const res = rec(this)
    res.forEach((n, i) => {
        this[i] = n
    })
    console.log(this)
}
const arr = [2, 4, 5, 3, 1]
arr.quickSort()
// 快速排序时间复杂度为nlogn，快速排序性能比冒泡和选择和插入要好，谷歌sort曾用快排实现
